package com.service;

import com.dao.AccountDao;
import com.database.common.Service;
import com.pojo.Account;

/**
 * Created with IntelliJ IDEA by ChouFy on 2020-02-28.
 *
 * @author zhoufy
 */
@Service(name = "abcd")
public class TransferServiceImpl implements TransferService {

    private AccountDao accountDao;


    @Override
    public void transfer(String fromAccountNo, String toAccountNo, int money) {


        Account fromAccount = accountDao.getAccountByAccountNo(fromAccountNo);
        Account toAccount = accountDao.getAccountByAccountNo(toAccountNo);

        fromAccount.setMoney(fromAccount.getMoney() - money);
        toAccount.setMoney(toAccount.getMoney() + money);

        accountDao.updateAccountInfoByAccountNo(fromAccount);
        accountDao.updateAccountInfoByAccountNo(toAccount);

    }
}
